#include<bits/stdc++.h>
using namespace std;
#define int long long
class unionfind
{
public:
	
	vector<int> parent;
	vector<int> rank;
	unionfind(int n)
	{
		parent.resize(n);
		rank.resize(n, 1);
		for (int i = 0; i < n; i++) {
			parent[i] = i;
		}
	};
	int find(int x)
	{
		if (parent[x] != x) {
			parent[x] = find(parent[x]);
		}
		return parent[x];
	}
	void unite(int x, int y)
	{
		int rx = find(x);
		int ry = find(y);
		if (rank[rx] < rank[ry]) {
			parent[rx] = ry;
		} else if (rank[rx] > rank [ry]) {
			parent[ry] = rx;
		} else {
			parent[ry] = rx;
			rank[rx] ++;
		}
	}
	
};
signed main()
{
	int n, m;
	cin >> n >> m;
	int op;
	unionfind u(n);
	int a, b;
	while (m--) {
		cin >> op;
		cin >> a >> b;
		if (op == 1) {
			u.unite(a, b);
		} else if (op == 2) {
			if (u.find(a) == u.find(b)) {
				cout << "Y" << endl;
			} else cout << "N" << endl;
		}
		
	}
	cout << "a";
	return 0;
}
